﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Triunfadores.BusinessEntities;

namespace Triunfadores.Repository.Mapping
{
    public class BeneficiarioMap:EntityTypeConfiguration<Beneficiario>
    {
        public BeneficiarioMap()
        {
            //clave primaria y que sea autoincremental
            this.HasKey(tc => tc.Id);
            this.Property(tc => tc.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            //propiedades
            this.Property(tc => tc.Apellidos)
                .HasColumnType("varchar")
                .HasMaxLength(50)
                .IsRequired();
            this.Property(tc => tc.Direccion)
                .HasColumnType("varchar")
                .HasMaxLength(100)
                .IsRequired();
            this.Property(tc => tc.Dni)
                .HasColumnType("char")
                .HasMaxLength(8)
                .IsRequired();
            this.Property(tc => tc.Email)
                .HasColumnType("varchar")
                .HasMaxLength(50)
                .IsRequired();
            this.Property(tc => tc.Nombres)
                .HasColumnType("varchar")
                .HasMaxLength(50)
                .IsRequired();
            this.Property(tc => tc.Telefono)
                .HasColumnType("varchar")
                .HasMaxLength(11)
                .IsRequired();

            //un beneficiario va a a tener un lugar
            this.HasRequired(cp => cp.LugarDireccion)
                .WithMany(cp => cp.IcUbigeoBeneficiarios)
                .HasForeignKey(cp => cp.IdLugarDireccion)
                .WillCascadeOnDelete(false);

        }
    }
}
